#ifndef UPLOAD_FILE_H
#define UPLOAD_FILE_H

#include <QtNetwork>
#include <QHostAddress>
#include <QMessageBox>
#include <QDataStream>
#include <QByteArray>
#include <QDebug>
#include <QDateTime>
#include <QFile>
#include <QFileDialog>


#include "../sql.h"
class upload_file : public QObject
{
    Q_OBJECT
public:
    explicit upload_file(QObject *parent = nullptr);

    void startListen(unsigned short port);
    void Upload(QString path);    //发送文件
    void sendfile(QString path);
protected:
    //发送文件数据
    void sendfileData();

signals:
    //通知主线程断开连接
    void gameover();
    void file_path(QString path);
    /**
     * @brief finish 完成传输
     */
    void finish();

private slots:

private:
    void UploadFile();
    QTcpServer *fileserver;
    QTcpSocket *fileSocket;

    QTimer *timer;

    // 文件传送
    QString filename;
    QFile file; //文件对象
    qint64 filesize = 0;//文件大小
    qint64 sendfilesize = 0;//已发送大小

    QTimer *timer2;
    QQueue<QString> file_queue;

    QTimer *timer3;

    sql *mysql = nullptr;

};

#endif // UPLOAD_FILE_H
